package com.uenpay.oem.ui.reserver;

import android.text.TextUtils;

import com.uenpay.oem.data.modelImpl.BankCardModel;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.util.net.listener.HttpResultListener;

/**
 * Created by DELL on 2017/6/20.
 */

public class ReservedcodePresenter implements AddnewcardContract.Pesenter {
    AddnewcardContract.View mView;
    BankCardModel mModel;
    BankCardInfo info;
    /**
     * 添加银行卡的回调结果
     */
    private HttpResultListener resultListener = new HttpResultListener() {
        @Override
        public void onStart() {
            super.onStart();
            mView.showLoading();
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            mView.dismissLoading();
            //mView.showToast("添加银行卡失败，请稍候重试");
        }

        @Override
        public void onCancel() {
            super.onCancel();
            mView.dismissLoading();
        }

        @Override
        public void onComplete() {
            super.onComplete();
            mView.dismissLoading();

            ((ReservedcodeActivity)mView).goSuccessActivity();
        }
    };

    public ReservedcodePresenter(AddnewcardContract.View view) {
        mView = view;
        mModel = new BankCardModel();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public boolean checkData(String... data) {
        if (TextUtils.isEmpty(data[0])) {
            mView.showToast("手机号不能为空");
            return false;
        }
        if (TextUtils.isEmpty(data[1])) {
            mView.showToast("有效期不能为空");
            return false;
        }
        if (TextUtils.isEmpty(data[2])) {
            mView.showToast("请输入安全码");
            return false;
        }
        return true;
    }

    public void addCard(BankCardInfo info) {

        mModel.saveUserBank(info, resultListener);
    }
}
